package com.mdb.open.trade.validator;

import com.mdb.bc.api.data.ResultEx;
import com.mdb.bc.utils.ObjectUtil;
import com.mdb.enums.product.ProductCodeEnum;
import com.mdb.open.common.enums.product.ProductOpenStatusEnum;
import com.mdb.open.common.enums.trade.status.MerchantApproveStatusEnum;
import com.mdb.open.common.enums.trade.status.MerchantStatusEnum;
import com.mdb.open.trade.domain.po.product.CustProd;
import com.mdb.open.trade.domain.po.trade.MerchantInfo;
import com.mdb.open.trade.service.product.CustProdService;
import com.mdb.open.trade.service.trade.TfMerchantInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//import com.mdb.enums.product.ProductOpenStatusEnum;

/**
 * @description:
 * @author: you.yichao
 * @create: 2019-08-01 11:12
 **/
@Component
public class CheckMultiStatusValidator {


    @Autowired
    CustProdService custProdService;

    @Autowired
    TfMerchantInfoService tfMerchantInfoService;


    public Boolean checkCustomerStatus(String customerCode) {

        return this.checkProductStatus(customerCode);
    }

    public Boolean checkMerchantStatus(String customerCode, String merchantNo) {
        Boolean cusStatus = checkCustomerStatus(customerCode);
        if (!cusStatus) {
            return false;
        }

        ResultEx<MerchantInfo> merEx = tfMerchantInfoService.getMerchantInfo(customerCode, merchantNo);
        if (merEx.isFailed()) {
            return false;
        }
        if (ObjectUtil.isEmpty(merEx.getData())) {
            return false;
        }

        if (!MerchantStatusEnum.NORMAL.equals(merEx.getData().getStatus())) {
            return false;
        }


        return MerchantApproveStatusEnum.MODEL_APPROVED.equals(merEx.getData().getApproveStatus());
    }

    public Boolean checkProductStatus(String customerCode) {
        CustProd custProd = custProdService.getByCustProdCode(customerCode, ProductCodeEnum.TF01.getValue());
        if (ObjectUtil.isEmpty(custProd)) {
            return false;
        }
        if (ProductOpenStatusEnum.NORMAL.getValue().equals(custProd.getStatus())) {
            return true;
        }
        return false;
    }


    public Boolean checkMerchantCustomer(String customerCode, String merchantNo) {

        ResultEx<MerchantInfo> infoEx = tfMerchantInfoService.getMerchantInfo(customerCode, merchantNo);
        if (infoEx.isFailed() || ObjectUtil.isEmpty(infoEx.getData())) {
            return false;
        }
        return true;

    }

}
